var cache = applicationCache;
if(cache) {
  cache.oncached = function () {
    console.log("-- cached");
  }

  cache.onchecking = function() {
    console.log("-- checking");
  }

  cache.ondownloading = function() {
    console.log("-- downloading");
  }

  cache.onerror = function() {
    console.log("-- error");
  }

  cache.onnoupdate = function() {
    console.log("-- noupdate");
  }

  cache.onobsolete = function() {
    console.log("-- obsolete");
  }

  cache.onprogress = function() {
    console.log("-- porgress");
  }

 //是否在线
  // window.addEventListener('offline', function(){
  //   console.log('offline');
  //  }, false)
  // window.addEventListener('online', function(){
  //   console.log('offline');
  //  }, false)
  
  // navigator.onLine 
  // navigator.offLine 

  window.onload = function() {
    cache.onupdateready = function(event) {  //更新缓存文件 
      if(cache.status == cache.UPDATEREADY) { // 
        console.log("-- updateready");
       // 成功下载最新资源，更新缓存
        cache.swapCache();
        if(confirm('a new version of this site is avaiable, load it?')) {
          location.reload();
        }
      }
    }
  }
} else {
  console.log('your browser not suppert application cache')
}